package com.rt.web.controller.system;

import java.util.List;

import com.rt.common.utils.StringUtils;
import com.rt.system.domain.RtImportanceInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rt.common.annotation.Log;
import com.rt.common.core.controller.BaseController;
import com.rt.common.core.domain.AjaxResult;
import com.rt.common.enums.BusinessType;
import com.rt.system.domain.RtKnowledgeInfo;
import com.rt.system.service.IRtKnowledgeInfoService;
import com.rt.common.utils.poi.ExcelUtil;
import com.rt.common.core.page.TableDataInfo;

/**
 * 大纲Controller
 * 
 * @author Yg
 * @date 2022-04-13
 */
@RestController
@RequestMapping("/system/info")
public class RtKnowledgeInfoController extends BaseController
{
    @Autowired
    private IRtKnowledgeInfoService rtKnowledgeInfoService;

    /**
     * 查询大纲列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(RtKnowledgeInfo rtKnowledgeInfo)
    {
        startPage();
        List<RtKnowledgeInfo> list = rtKnowledgeInfoService.selectRtKnowledgeInfoList(rtKnowledgeInfo);
        return getDataTable(list);
    }

    /**
     * 查询大纲知识点可用列表
     */
    @GetMapping("/availableList")
    public TableDataInfo availableList(RtKnowledgeInfo rtKnowledgeInfo)
    {
        rtKnowledgeInfo.setStatus(1);
        List<RtKnowledgeInfo> list = rtKnowledgeInfoService.selectRtKnowledgeInfoList(rtKnowledgeInfo);
        return getDataTable(list);
    }

    /**
     * 查询重要度列表
     */
    @GetMapping("/importance")
    public TableDataInfo list(RtImportanceInfo rtImportanceInfo)
    {
        startPage();
        List<RtImportanceInfo> list = rtKnowledgeInfoService.selectRtImportanceInfoList(rtImportanceInfo);
        return getDataTable(list);
    }

    /**
     * 导出大纲列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "大纲", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RtKnowledgeInfo rtKnowledgeInfo)
    {
        List<RtKnowledgeInfo> list = rtKnowledgeInfoService.selectRtKnowledgeInfoList(rtKnowledgeInfo);
        ExcelUtil<RtKnowledgeInfo> util = new ExcelUtil<RtKnowledgeInfo>(RtKnowledgeInfo.class);
        return util.exportExcel(list, "大纲数据");
    }

    /**
     * 获取大纲详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rtKnowledgeInfoService.selectRtKnowledgeInfoById(id));
    }

    /**
     * 新增大纲
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "大纲", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RtKnowledgeInfo rtKnowledgeInfo)
    {
//        if (StringUtils.isNotNull(rtKnowledgeInfoService.selectRtKnowledgeInfoByName(rtKnowledgeInfo))){
//            return AjaxResult.error("大纲或编码已存在");
//        }
        rtKnowledgeInfo.setCreateOperator(getUsername());
        return toAjax(rtKnowledgeInfoService.insertRtKnowledgeInfo(rtKnowledgeInfo));
    }

    /**
     * 修改大纲
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "大纲", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RtKnowledgeInfo rtKnowledgeInfo)
    {
//        if (StringUtils.isNotNull(rtKnowledgeInfoService.selectRtKnowledgeInfoByName(rtKnowledgeInfo))){
//            return AjaxResult.error("大纲或编码已存在");
//        }
        rtKnowledgeInfo.setUpdateOperator(getUsername());
        return toAjax(rtKnowledgeInfoService.updateRtKnowledgeInfo(rtKnowledgeInfo));
    }

    /**
     * 删除大纲
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "大纲", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(rtKnowledgeInfoService.deleteRtKnowledgeInfoById(id));
    }
}
